﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using lauimini_webform.BLL;
using lauimini_webform.Data;
namespace lauimini_webform
{
    public partial class Add : System.Web.UI.Page
    {
        MyDBContext dB;
        protected void Page_Load(object sender, EventArgs e)
        {
            dB = new MyDBContext();
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Title.Text = string.Empty;
            decription.Text = string.Empty;
            StartTime.Text = string.Empty;
            EndTime.Text = string.Empty;
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            UserTargetService userTargetService = new UserTargetService();
            string userAccount = Session["userAccount"].ToString();
            UserService userService = new UserService();

            int userid = new UserService().getUserid(userAccount);
            int row = userTargetService.addTarget(Title.Text, decription.Text, StartTime.Text, EndTime.Text, userid);
            if (row == 200)
            {
                Response.Write("<script>alert('添加成功');</script>");
            }
            if (row == -1)
            {
                Response.Write("<script>alert('结束时间不能小于开始时间');</script>");
            }
            if (row == 0)
            {
                Response.Write("<script>alert('早上7点前和晚上24点是休息时间哦，添加失败');</script>");
            }




        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/index.aspx");
        }
    }
}